<?php

namespace App\Http\Controllers\Admin\Auth;

use App\User;
use Validator;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ThrottlesLogins;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;
use Captcha;

class AuthController extends Controller
{
    //登录成功后的跳转地址
    protected $redirectPath = '/admin/index';
    /*
    |--------------------------------------------------------------------------
    | Registration & Login Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles the registration of new users, as well as the
    | authentication of existing users. By default, this controller uses
    | a simple trait to add these behaviors. Why don't you explore it?
    |
    */

    use AuthenticatesAndRegistersUsers, ThrottlesLogins;

    /**
     * Create a new authentication controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('guest', ['except' => 'getLogout']);
    }

    /**
     * Get a validator for an incoming registration request.
     *
     * @param  array  $data
     * @return \Illuminate\Contracts\Validation\Validator
     */
    protected function validator(array $data)
    {
    //     $messages = [
    // 'required' => ':attribute 的字段是必要的。',
    //         ];

        $messages = [
            'required'    => ':attribute 是必填字段',
            'size'        => ':attribute 手机号不是11位',
            'email'       => ':attribute  邮箱格式不正确',
            'password'    => ':attribute  密码至少6位',

        ];
        return Validator::make($data, [
            'name' => 'required|max:255',
            'email' => 'required|email|max:255|unique:users',
            'password' => 'required|confirmed|min:6',
            'mobile'=>'required|size:11',
            'verify'  =>'required',
        ],$messages);
    }

    /**
     * Create a new user instance after a valid registration.
     *
     * @param  array  $data
     * @return User
     */
    protected function create(array $data)
    {
        $user =  User::create([
            'name' => $data['name'],
            'email' => $data['email'],
            'password' => bcrypt($data['password']),
            'mobile'=>$data['mobile'],
        ]);

        return $user;
    }

    /*
    * 生成验证码
    */
    public  function  Verify()
    {
       return  Captcha::src();
    }

   /*
    * 验证验证码
    */

    public  function VerifyCode($code)
    {
        return Captcha::check($code);
    }

   
}
